#include<bits/stdc++.h>
#define N 1000005
using namespace std;
int n;
int cnt,c[N][2],p[N];
int tot,rt[N];
int ans;
char s[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > e[N];
int merge(int x,int y){
    if(e[x].size()<e[y].size()) swap(x,y);
    while(!e[y].empty()) e[x].push(e[y].top()),e[y].pop();
    return x;
}
void dfs(int x,int d){
    rt[x]=++tot;
    if(c[x][0]) dfs(c[x][0],d+1),rt[x]=merge(rt[x],rt[c[x][0]]);
    if(c[x][1]) dfs(c[x][1],d+1),rt[x]=merge(rt[x],rt[c[x][1]]);
    if(!c[x][0]&&!c[x][1]) e[rt[x]].push({d,0});
    if(c[x][0]&&!c[x][1]) e[rt[x]].push({d+1,0});
    if(c[x][1]&&!c[x][0]) e[rt[x]].push({d+1,0});
    while(p[x]--){
        pair<int,int> w=e[rt[x]].top();
        int a=w.first,b=w.second;
        e[rt[x]].pop();
        ans+=a-d;
        if(b==0) e[rt[x]].push({a+2,1});
        else e[rt[x]].push({a+1,1}),e[rt[x]].push({a+1,1});
    }
}
signed main(){
    freopen("id.in","r",stdin);
    freopen("id.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s+1);
        int len=strlen(s+1),now=0;
        for(int j=1;j<=len;j++){
            if(!c[now][s[j]-'0']) c[now][s[j]-'0']=++cnt;
            now=c[now][s[j]-'0'];
        }
        p[now]++;
    }
    dfs(0,0);
    printf("%d\n",ans);
    return 0;
}